<?php
/**
 * 企业trait
 * User: dxk
 * Date: 2020/07/15
 */
namespace App\Traits;
trait SingleInstanceTrait
{
    protected static $instance = [];

    /**
     * 单例模式
     * @param mixed ...$args
     * @return static
     */
    public static function getInstance(...$args)
    {
        $class = static::class;
        $class_k = md5(serialize([$class, $args]));
        if (!isset(static::$instance[$class_k]) || !(static::$instance[$class_k] instanceof self)) {
            static::$instance[$class_k] = new static(...$args);
        }
        return static::$instance[$class_k];
    }
}
